package com.clear.honghefinance.admin.controller;

import com.clear.honghefinance.biz.modules.assist_calculate.domain.dto.CreateAssistCalculateCategoryDTO;
import com.clear.honghefinance.biz.modules.assist_calculate.domain.dto.DeleteAssistCalculateCategoryDTO;
import com.clear.honghefinance.biz.modules.assist_calculate.domain.dto.UpdateAssistCalculateCategoryDTO;
import com.clear.honghefinance.biz.modules.assist_calculate.domain.vo.GetAssistCalculateCategoryDetailVO;
import com.clear.honghefinance.biz.modules.assist_calculate.domain.vo.ListAssistCalculateCategoryVO;
import com.clear.honghefinance.biz.modules.assist_calculate.service.IAssistCalculateCateService;
import com.clear.honghefinance.common.dto.entity.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 辅助核算类别管理Controller
 */
@Api(tags = "辅助核算类别管理")
@RestController
@RequestMapping(value = "/assistCalculateCate")
@Slf4j
@RequiredArgsConstructor
public class AssistCalculateCategoryController {
    private final IAssistCalculateCateService assistCalculateCateService;

    /**
     * 添加辅助核算类别
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "添加辅助核算类别")
    @PostMapping(value = "/create")
    public ApiResponse<Boolean> create(@Validated @RequestBody CreateAssistCalculateCategoryDTO dto) {
        return ApiResponse.success(assistCalculateCateService.create(dto));
    }

    /**
     * 创建辅助核算类别
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "修改辅助核算类别")
    @PostMapping(value = "/update")
    public ApiResponse<Boolean> update(@Validated @RequestBody UpdateAssistCalculateCategoryDTO dto) {
        return ApiResponse.success(assistCalculateCateService.update(dto));
    }


    /**
     * 删除辅助核算类别
     *
     * @param dto req
     * @return
     */
    @ApiOperation(value = "删除辅助核算类别")
    @PostMapping(value = "/del")
    public ApiResponse<Boolean> del(@Validated @RequestBody DeleteAssistCalculateCategoryDTO dto) {
        return ApiResponse.success(assistCalculateCateService.delete(dto));
    }


    /**
     * 查询辅助核算类别列表
     *
     * @return
     */
    @ApiOperation(value = "查询辅助核算类别列表")
    @GetMapping(value = "/list")
    public ApiResponse<List<ListAssistCalculateCategoryVO>> list() {
        return ApiResponse.success(assistCalculateCateService.listAll());
    }


    /**
     * 查询辅助核算类别列表
     *
     * @param id 辅助核算类别id
     * @return
     */
    @ApiOperation(value = "获取辅助核算类别详情")
    @GetMapping(value = "/get")
    public ApiResponse<GetAssistCalculateCategoryDetailVO> get(@Validated @NotNull(message = "辅助核算类别id不能为空")
                                                               @Min(value = 1) @RequestParam long id) {
        return ApiResponse.success(assistCalculateCateService.getDetailById(id));
    }
}

